package com.ccx.coachsite.http;

import android.os.AsyncTask;

/**
 *  The HTTP request async
 *  @author caijj
 *  
 *  @version 1.0
 */
public abstract class HttpRequestAsync extends AsyncTask<Void, Void, Response>{

	HttpRequest mHttpRequest;
	String url;

	public HttpRequestAsync(HttpRequest request) {
		this.mHttpRequest = request;
	}

	public void request(String url) {
		this.url = url;
		execute();
	}

	@Override
	protected final Response doInBackground(Void... params) {
		BaseResp result = (BaseResp) mHttpRequest.execute(url);
		return result;
	}

	@Override
	protected final void onPostExecute(Response resp) {
		response(resp);
		mHttpRequest.release(); // release HTTP resources
	}

	@Override
	protected final void onPreExecute() {
	}

	public abstract void response(Response resp);
}
